package org.example.eee.controller;

import org.example.eee.common.JsonCode;
import org.example.eee.entity.Student;
import org.example.eee.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/getAll")
    public List<Student> getAll() {
        List<Student> all = studentService.getAll();
        return all;
    }

    @GetMapping("/getById")
    public Student getById(Integer id) {
        Student byId = studentService.getById(id);
        return byId;
    }

    @PostMapping("/insert")
    public JsonCode insert(Student student) {
        studentService.insert(student);
        return JsonCode.getJson();
    }

    @PostMapping("/update")
    public JsonCode update(Student student) {
        studentService.update(student);
        return JsonCode.getJson();
    }

    @PostMapping("/delete")
    public JsonCode delete(Integer id) {
        studentService.delete(id);
        return JsonCode.getJson();
    }
}
